package com.jsh.erp.controller;

import com.jsh.erp.base.AjaxResult;
import com.jsh.erp.base.BaseController;
import com.jsh.erp.base.TableDataInfo;
import com.jsh.erp.datasource.req.ProductionTaskAddReq;
import com.jsh.erp.datasource.vo.ProductionTaskVo;
import com.jsh.erp.service.ProductionTaskService;
import com.jsh.erp.utils.BaseResponseInfo;
import com.jsh.erp.utils.Constants;
import com.jsh.erp.utils.StringUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * @author : yy
 * @date: 2025/8/1 14:48
 * @description:
 */
@RestController
@RequestMapping("/production/task")
public class ProductionTaskController extends BaseController {

    @Autowired
    private ProductionTaskService productionTaskService;

    /**
     * 分页查询生产任务
     */
    @GetMapping("/list")
    public TableDataInfo getProductionTasks(@RequestParam(value = Constants.SEARCH, required = false) String search,
                                            HttpServletRequest request) {
        String orderNumber = StringUtil.getInfo(search, "orderNumber");
        String productInfo = StringUtil.getInfo(search, "productInfo");
        String singleDateStart = StringUtil.getInfo(search, "singleDateStart");
        String singleDateEnd = StringUtil.getInfo(search, "singleDateEnd");
        String salesOrderNumber = StringUtil.getInfo(search, "salesOrderNumber");
        String planCompletionStart = StringUtil.getInfo(search, "planCompletionStart");
        String planCompletionEnd = StringUtil.getInfo(search, "planCompletionEnd");
        String singleStatus = StringUtil.getInfo(search, "singleStatus");
        String customerOriginalNumber = StringUtil.getInfo(search, "customerOriginalNumber");
        List<ProductionTaskVo> list = productionTaskService.select(orderNumber, productInfo, singleDateStart,
                singleDateEnd, salesOrderNumber, planCompletionStart, planCompletionEnd, singleStatus,customerOriginalNumber);
        return getDataTable(list);
    }

    @PostMapping("/add")
    public BaseResponseInfo add(@RequestBody ProductionTaskAddReq productionTaskAddReq) throws Exception {
        return productionTaskService.add(productionTaskAddReq);
    }
    @PutMapping("/update")
    public BaseResponseInfo update(@RequestBody ProductionTaskAddReq productionTaskAddReq) {
        return productionTaskService.update(productionTaskAddReq);
    }

    @PostMapping("/delete")
    public BaseResponseInfo delete(@RequestBody Long[] ids) {
        return productionTaskService.delete(ids);
    }

    @GetMapping("getMaterialByTaskId")
    public BaseResponseInfo getMaterialByTaskId(@RequestParam("taskId") Long taskId) {
        return productionTaskService.getMaterialByTaskId(taskId);
    }
    @GetMapping("getProcessByTaskId")
    public BaseResponseInfo getProcessByTaskId(@RequestParam("taskId") Long taskId) {
        return productionTaskService.getProcessByTaskId(taskId);
    }
}
